
// <copyright file="PingTelnetHelper.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The ping telnet helper.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Net
{
    /// <summary>
    /// The ping telnet helper.
    /// </summary>
    public sealed class PingTelnetHelper : AbstractDisposable
    {
        #region Fields

        /// <summary>
        /// The command prompt.
        /// </summary>
        private readonly string _commandPrompt;

        /// <summary>
        /// The telnet helper.
        /// </summary>
        private readonly TelnetHelper _telnetHelper;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="PingTelnetHelper"/> class.
        /// </summary>
        /// <param name="telnetHelper">
        /// The telnet helper.
        /// </param>
        /// <param name="commandPrompt">
        /// The command prompt.
        /// </param>
        public PingTelnetHelper(TelnetHelper telnetHelper, string commandPrompt)
        {
            this._telnetHelper = telnetHelper;
            this._commandPrompt = commandPrompt;
        }

        /// <summary>
        /// Finalizes an instance of the <see cref="PingTelnetHelper"/> class.
        /// </summary>
        ~PingTelnetHelper()
        {
            this.Dispose(false);
        }

        #endregion Constructors and Finalizers

        #region Public Properties

        /// <summary>
        /// Gets the telnet helper.
        /// </summary>
        public TelnetHelper TelnetHelper
        {
            get
            {
                return this._telnetHelper;
            }
        }

        #endregion Public Properties

        #region Public Methods and Operators

        /// <summary>
        /// The ping ip address.
        /// </summary>
        /// <param name="ipAddress">
        /// The ip address.
        /// </param>
        /// <param name="resultProcessor">
        /// The result processor.
        /// </param>
        /// <param name="timeoutInMilliSeconds">
        /// The timeout in milli seconds.
        /// </param>
        /// <returns>
        /// The <see cref="decimal"/>.
        /// </returns>
        public decimal PingIpAddress(string ipAddress, IPingResultProcessor resultProcessor, int timeoutInMilliSeconds)
        {
            string r = this._telnetHelper.SendCommand("ping " + ipAddress, this._commandPrompt, timeoutInMilliSeconds);
            return resultProcessor.ProcessPingResult(r, this._commandPrompt);
        }

        #endregion Public Methods and Operators

        #region Methods

        /// <summary>
        /// The dispose.
        /// </summary>
        /// <param name="disposing">
        /// The disposing.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            this._telnetHelper.Dispose();
        }

        #endregion Methods
    }
}
